package com.marst.first.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.marst.first.bean.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from user where account = #{account} and is_delete=0")
    User getUserInfoAccount(String account);

    @Select("select count(1) from user where account = #{account} and is_delete=0")
    int getUserCountByAccount(String account);

    @Update("update user set  is_delete = 1 where id = #{id}")
    void deleteUserOnLogic(int id);

    @Select("select * from user a where a.id = #{id}")
    User getUserById(int id);

    @Select("<script>                                                 "+
            "SELECT                                                   "+
            "	*                                                     "+
            "FROM                                                     "+
            "	user                                                  "+
            "WHERE                                                    "+
            "	is_delete = 0                                         "+
            "   <if test=\" account != null and account != '' \">     " +
            "	AND account LIKE CONCAT('%','${account}','%' )        "+
            "	</if>                                                 "+
            "   <if test=\" name != null and name != '' \">           " +
            "	AND `name` LIKE CONCAT('%','${name}','%' )            "+
            "	</if>                                                 "+
            "	</script>                                              ")
    List<User> getUserList(String account, String name);




    @Select("select count(1) from user where account = #{account} and id!=#{id} and is_delete=0")
    int getUserCountForUpdate(String account , int id);
}
